var app = getApp();
var server = require('../../utils/server');
Page({
	data: {
		img_url: 'http://17fx.com/imgs/',
    is_show:false,
    num:0,
    userInfo:[],
    subscribe: 1,
    is_shop:0,
    suppliers_id:0
	},

  // isshow:function(){
  //   this.setData({
  //     is_show:true
  //   })
  // },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    if (app.globalData.userid == 0){
      //登录调用
      getApp().getUserInfo(function (userInfo, openid1) { })
    }
    that.setData({
      userInfo: app.globalData.userInfo,
      userid: app.globalData.userid,
      subscribe: getApp().globalData.subscribe
    });
    wx.request({
      url: 'https://17fx.com/weapp/Adminapi/getuser.html',
      data: {
        user_id: app.globalData.userid
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        that.setData({
          is_shop: res.data.is_shop
        })
      }
    });
  },

  //跳转到商家控制台
  shopadmin:function(){
    wx.navigateTo({ url: '../shopadmin/shopadmin' });
  },

  //拨打电话
  isshow: function (event) {
    //console.log('点击事件primary1,id:' + event.currentTarget.dataset.id )
    wx.makePhoneCall({
      phoneNumber: '073188888025' //仅为示例，并非真实的电话号码
    })
  },
  closeshow:function(){
    this.setData({
      is_show:false
    })
  },
  isshow2:function(){
    this.setData({
      is_show: true
    })
    var that = this;
    if(that.data.num == 0){
      wx.getImageInfo({
        src: 'https://17fx.com/imgs/kefuewm.jpg',
        success: function (res) {

          wx.saveImageToPhotosAlbum({
            filePath: res.path,
            success(res) {
              console.log(res);
              that.setData({
                num:1
              })
            },
            fail: function () {
              console.log('fail');
            },
            complete: function () {
              wx.showToast({
                title: '二维码已保存到相册',
                icon: 'success',
                duration: 3000
              })
              
            }
          })
        }
      })
    }else{
      wx.showToast({
        title: '二维码已保存到相册',
        icon: 'success',
        duration: 3000
      })
    }

  },
  //跳转到关注页面
  guanzhupage: function () {
    wx.navigateTo({ url: '../index/guanzhu' });
  },

	onShow: function () {

	},
	setTap: function () {
		wx.navigateTo({
			url: 'account',
			success: function (res) {
				// success
			},
			fail: function () {
				// fail
			},
			complete: function () {
				// complete
			}
		})
	},
	voucherTap: function () {
		wx.navigateTo({
			url: 'voucher',
			success: function (res) {
				// success
			},
			fail: function () {
				// fail
			},
			complete: function () {
				// complete
			}
		})
	},

  //我的订单
	prizeTap: function () {
    wx.switchTab({
			url: '../order/order',
			success: function (res) {
				// success
			},
			fail: function () {
				// fail
			},
			complete: function () {
				// complete
			}
		})
	},
  //跳转到 我的收益订单
  shouyiorder:function(){
    wx.navigateTo({
      url: '../shopadmin/adminfanliorder',
    })
  },
  //跳转到 我推荐的会员
  adminuser:function(){
    wx.navigateTo({
      url: '../shopadmin/adminuser',
    })
  },
  //我的地址
  dizhiTap:function(){
    wx.navigateTo({
      url: 'dizhi',
    })
  },
	contactTap: function () {
		wx.makePhoneCall({
			phoneNumber: '13553835046'
		})
	},
  //拉取权限
  laquchuanxian:function(){
    var that = this;
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.userInfo']) {
          wx.authorize({
            scope: 'scope.userInfo',
            success() {
              // 用户已经同意小程序使用，后续调用 wx.getUserInfo 接口不会弹窗询问
              console.log("33333333333")
              wx.getUserInfo({
                success:function(res2){
                  app.globalData.userInfo = res2.userInfo
                  that.setData({
                    userInfo: res2.userInfo
                  })
                }
              })
            },
            fail:function(){
              console.log("22222222222")

            },
            complete:function(){

            }
          })
        }else{
          console.log("11111111")
          wx.getUserInfo({
            success: function (res2) {
              app.globalData.userInfo = res2.userInfo
              that.setData({
                userInfo: res2.userInfo
              })
            }
          })
        }
      }
    })

    
  }
});

